package com.base.cn.platform.os.common.logger;

import com.base.cn.platform.os.common.utils.DateUtils;
import com.base.cn.platform.os.common.utils.web.WebUtils;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 商品PV/UV日志
 *
 * @author s.li
 * @date 2019/04/24
 */
@Slf4j
public class GoodsGVUVLogger {

    /**
     * 生成商品PV/UV日志
     * @param request HttpServletRequest
     * @param goodsId 商品ID
     * @param goodsType 商品类型
     */
    public static synchronized void genGoodsPVUVLog(HttpServletRequest request,
                                                    BigDecimal goodsId,
                                                    String goodsType){
        BigDecimal tenantId = BigDecimal.ZERO;
        StringBuilder loginContext = new StringBuilder();
        String ip = WebUtils.getIpAddr(request);
        loginContext.append(ip).append("|").append(DateUtils.format(new Date(),"yyyy-MM-dd HH:mm")).append("|").append(goodsId).append("|").append(goodsType).append("|").append(tenantId);
        log.info(loginContext.toString());
    }
}
